package top.maof.book.rank.book;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.maof.book.map.BookMap;
import top.maof.book.model.Book;
import top.maof.book.rank.KeyGenerate;
import top.maof.book.type.HotType;

import java.util.Set;
import java.util.stream.Collectors;

@Slf4j
@Component
public class BookKeyGenerate implements KeyGenerate<BookPage> {
    @Override
    public Set<String> filter(Set<String> set) {
        set = set.stream().filter(s -> {
            if (s.contains("month")) {
                return s.contains("year");
            }
            return true;
        }).filter(s -> {
            if (s.contains("week")) {
                return s.contains("year") && s.contains("month");
            }
            return true;
        }).filter(s -> {
            if (s.contains("day")) {
                return s.contains("year") && s.contains("month");
            }
            return true;
        }).collect(Collectors.toSet());
        return set;
    }

    public static void main(String[] args) throws Exception {
        Book book = new Book();
        book.setState("完结");
        book.setClassify("仙侠");
        book.setSourceSite("起点");

        BookPage bookPage = BookMap.INSTANCE.toBookPage(book);
        bookPage.setHotType(HotType.CLICK);
        bookPage.initTime();
        BookKeyGenerate generate = new BookKeyGenerate();

        Set<String> strings = generate.generateKeys(bookPage);
        log.info("");
    }
}
